<template>
    <span class="diggit"  @click="tops()">很赞哦！ {{top}}</span>
</template>

<script>
    export default {
        data(){
            return {
                top:0,
            }
        },
        methods:{
            tops:function () {
                let _this = this;
                let data = {'article_id':_this.article_id,"top":this.top};
                let url = "/dealTop/";
                this.$http.post(url,data,{
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then(function(res){
                    if (res.data.code=='301') {
                        alert(res.data.msg);
                    } else {
                        _this.top = res.data.data.top;
                    }
                    return {
                        top:0,
                    }
                })
            }
        },
        mounted() {
            let _this = this;
            let data = {'article_id':_this.article_id};
            let url = "/dealTop";
            this.$http.post(url,data, {
                headers: {
                    'Content-Type': 'application/json'
                }
            }).then(function(res){
                _this.top = res.data.data.top;
            });
            return {
                top:0,
            }
        },
        props:{
            article_id:Number,
        },watch:{
            top:function () {
                console.log(this.top);
            }
        }
    }
</script>
